home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / misc / TownMaze.lha / TownMaze / src.lzh / makecourts.c < prev    next >
C/C++ Source or Header  |  1991-08-04  |  2KB  |  75 lines

  1. /*
  2. ** makecourts.c  Copyright 1991 Kent Paul Dolan,
  3. **               Mountain View, CA, USA 94039-0755
  4. **
  5. ** Written to satisfy an inquiry on USENet's rec.games.programmer newsgroup.
  6. ** May be freely used or modified in any non-commercial work.  Copyrighted
  7. ** only to prevent patenting by someone else.
  8. */
  9.  
  10. #include <stdio.h>
  11. #include "townmaze.h"
  12. #include "townproto.h"
  13.  
  14. #ifdef __STDC__
  15. void makecourts()
  16. #else
  17. int makecourts()
  18. #endif
  19. {
  20.  
  21.   int totalcells;
  22.   int chosencell;
  23.   int tries;
  24.   int i;
  25.  
  26. /*
  27. ** Pepper courts around the city interior; keep them apart for algorithmic
  28. ** robustness reasons.
  29. */
  30.  
  31. #if PROGRESS
  32.   fprintf(stderr,"Courts ");
  33. #endif
  34.  
  35.   totalcells = ((mazeheight-1)/2 * (mazewidth-1)/2);
  36.  
  37.   for (i = 0; i < mazecourts; i++)
  38.   {
  39.  
  40. /*  fprintf(stderr,"Court %d\n",i); */
  41.  
  42. /*
  43. ** Set up to prevent infinite loop from unforseen geometry problems.
  44. */
  45.  
  46.    tries = 0;
  47.  
  48. /*
  49. ** Keep looking until a candidate cell is found for this ith court.
  50. */
  51.     do
  52.     {
  53.       /* not perfectly fair, but good enough for moderate sized mazes. */
  54.       chosencell = RANDOM()%totalcells;
  55.  
  56. /*    fprintf(stderr,"  chosencell %d\n",chosencell); */
  57.  
  58.       tries++;
  59.  
  60.     } while (   (tries <= MAXTRIES)
  61.              && (
  62.                     (interiorcell(chosencell) != (1==1))
  63.                  || (statlist[chosencell].status != ISOLATED)
  64.                  || (statlist[nhbris(chosencell,0)].status != ISOLATED)
  65.                  || (statlist[nhbris(chosencell,1)].status != ISOLATED)
  66.                  || (statlist[nhbris(chosencell,2)].status != ISOLATED)
  67.                  || (statlist[nhbris(chosencell,3)].status != ISOLATED)
  68.                 )
  69.             );
  70.  
  71.     if (tries <= MAXTRIES) makestreet(chosencell,streetnumct++,RANDOM()%4);
  72.   }
  73.   return;
  74. }
  75.